﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpNoisePCL.Noise
{
    public class RandomNoise : INoiseGenerator
    {

        float[] RandomArray1D;
        float[,] RandomArray2D;

        private int arraySize;

        public RandomNoise()
        {
            arraySize = 256; // Default Value
        }

        public int ArraySize
        {
            get { return arraySize; }
            set { arraySize = value; }
        }


        private void InitArray1D()
        {
            RandomArray1D = new float[ArraySize];
            Random r = new Random();
            for (int i = 0; i < ArraySize; i++)
            {
                RandomArray1D[i] = (float)r.NextDouble();
            }
        }

        private void InitArray2D()
        {
            RandomArray2D = new float[ArraySize, ArraySize];
            Random r = new Random();
            for (int i = 0; i < ArraySize; i++)
            {
                for (int j = 0; j < ArraySize; j++)
                {
                    RandomArray2D[i, j] = (float)r.NextDouble();
                }
            }
        }

        public float Get1D(float x)
        {
            if (RandomArray1D == null) InitArray1D();
            int ix = (int)x;
            return RandomArray1D[ix % (arraySize - 1)];
        }

        public float Get2D(float x, float y)
        {
            if (RandomArray2D == null) InitArray2D();
            int ix = (int)x;
            int iy = (int)y;
            return RandomArray2D[ix % (arraySize - 1), iy % (arraySize - 1)];

        }

        public float Get3D(float x, float y, float z)
        {
            throw new NotImplementedException();
        }

        public float Get4D(float x, float y, float z, float t)
        {
            throw new NotImplementedException();
        }
    }
}
